package base;

import java.util.*;
import java.io.*;

public class Word implements Serializable {
	private int x;               // toạ độ của kí tự đầu tiên
	private int y;
	private int length;         // độ dài chữ
	private int wordDirection; // hướng của chữ
	private int wordIndex;     // thứ tự trong cả ô chữ
	private int clueUsed = 0; // số gợi ý đã dùng
	private String word;
	private String clue1;
	private String clue2;
	private String clue3;
	private ArrayList letters; // chuỗi kí tự
	private boolean isSelected;
	private boolean isChecked = false;
	private boolean isHint = false;
	private boolean isEditable = true;

	public final static int DOWN = 0;
	public final static int ACROSS = 1;
	public final static int BIAS1 = 2;
	public final static int BIAS2 = 3;

	public Word(int x, int y, int wordDirection, int length) {
		this.x = x;
		this.y = y;
		this.wordDirection = wordDirection;
		this.length = length;
		clue1 = null;
		clue2 = null;
		clue3 = null;
		letters = new ArrayList(length);
		for (int i = 0; i < length; i++) {
			letters.add("*");
		}
		wordIndex = 0;
	}

	private void syncLetters() {
		for (int i = 0; i < length; i++) {
			char c = word.charAt(i);
			letters.set(i, String.valueOf(c));
		}
	}

	public void setLength(int a) {
		length = a;
	}

	public void setWordDirection(int a) {
		wordDirection = a;
	}

	public void setWord(String s) {
		word = s;
		syncLetters();
	}

	public String getWord() {
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < length; i++) {
			sb.append(letters.get(i));
		}
		return sb.toString();
	}

	public void setClue1(String s1) {
		clue1 = s1;
	}

	public void setClue2(String s2) {
		clue2 = s2;
	}

	public void setClue3(String s3) {
		clue3 = s3;
	}

	public String getClue1() {
		return clue1;
	}

	public String getClue2() {
		return clue2;
	}

	public String getClue3() {
		return clue3;
	}

	public void setClueUsed(int i) {
		clueUsed = i;
	}

	public int getClueUsed() {
		return clueUsed;
	}

	public int getWordDirection() {
		return wordDirection;
	}

	public void addLetter(String s, int index) {
		letters.set(index, s);
	}

	public ArrayList getLetters() {
		return letters;
	}

	public int getX() {
		return x;
	}

	public int getY() {
		return y;
	}

	public void setWordIndex(int i) {
		wordIndex = i;
	}

	public int getWordIndex() {
		return wordIndex;
	}

	public int getLength() {
		return length;
	}

	public boolean getIsSelected() {
		return isSelected;
	}

	public void setIsSelected(boolean b) {
		isSelected = b;
	}

	public boolean getIsChecked() {
		return isChecked;
	}

	public void setIsChecked(boolean b) {
		isChecked = b;
	}

	public boolean getIsHint() {
		return isHint;
	}

	public void setIsHint(boolean b) {
		isHint = b;
	}

	public boolean getIsEditable() {
		return isEditable;
	}

	public void setIsEditable(boolean b) {
		isEditable = b;
	}
}
